﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CJJCH.Web.Manage
{
    public partial class ManageList : PowerBase
    {
        CJJCH.BLL.T_NET_Manager bll_manager = new BLL.T_NET_Manager();
        protected void Page_Load(object sender, EventArgs e)
        {
            this.form1.DefaultButton = "btnSearch";
            if (!IsPostBack)
            {
                InitRequest();
                RepeaterDataBind();
            }
        }
        private void InitRequest()
        {
            if (!string.IsNullOrEmpty(Request.QueryString["keyword"]))
            {
                this.lblkeyword.Text = LTP.Common.StringClass.EncodeString(Request.QueryString["keyword"].ToString());
            }
        }
        private void RepeaterDataBind()
        {
            string keyword = LTP.Common.StringClass.EncodeString(this.lblkeyword.Text.Trim());
            IList<CJJCH.Model.T_NET_Manager> list = new List<CJJCH.Model.T_NET_Manager>();
            list = bll_manager.GetManagerList(keyword);
            this.rptManager.DataSource = list;
            this.rptManager.DataBind();
        }

        protected void rptManager_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                ((Label)e.Item.FindControl("lblRealName")).Text = ((CJJCH.Model.T_NET_Manager)e.Item.DataItem).RealName;
                ((Label)e.Item.FindControl("lblUserName")).Text = ((CJJCH.Model.T_NET_Manager)e.Item.DataItem).UserName;
                ((Label)e.Item.FindControl("lblUserTel")).Text = ((CJJCH.Model.T_NET_Manager)e.Item.DataItem).UserTel;
                ((LinkButton)e.Item.FindControl("lbtnEdit")).CommandArgument = ((CJJCH.Model.T_NET_Manager)e.Item.DataItem).ID.ToString();
                ((LinkButton)e.Item.FindControl("lbtnDel")).CommandArgument = ((CJJCH.Model.T_NET_Manager)e.Item.DataItem).ID.ToString();
                ((LinkButton)e.Item.FindControl("lbtnDel")).Attributes.Add("onclick", "javascript:if(confirm('确定要删除该数据吗？')){return true;}else{return false;}");                
            }
        }

        protected void lbtnEdit_Click(object sender, EventArgs e)
        {
            if (LTP.Common.CheckInput.CheckGUID(((LinkButton)sender).CommandArgument))
            {
                Response.Redirect("ManageEdit.aspx?ID="
                    + LTP.Common.StringClass.EncodeUrl(((LinkButton)sender).CommandArgument.ToString())
                    + "&keyword=" + LTP.Common.StringClass.EncodeUrl(lblkeyword.Text.Trim()));
            }
            else
            {
                LTP.Common.WindowClass.WindowBack("错误操作！");
            }
        }

        protected void lbtbDel_Click(object sender, EventArgs e)
        {
            if (LTP.Common.CheckInput.CheckGUID(((LinkButton)sender).CommandArgument))
            {
                string error = bll_manager.DelManager(new Guid(((LinkButton)sender).CommandArgument));
                if (error == "")
                {
                    Response.Redirect("ManageList.aspx?keyword=" + LTP.Common.StringClass.EncodeUrl(lblkeyword.Text.Trim()));
                }
                else
                {
                    LTP.Common.WindowClass.WindowBack(error);
                }
            }
            else
            {
                LTP.Common.WindowClass.WindowBack("操作错误！");
            }            
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
           this.lblkeyword.Text = LTP.Common.StringClass.EncodeString(this.txtKeyword.Text.Trim());
           RepeaterDataBind();
        }
    }
}